package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.cache.TDirtyWordCache;
import com.qf.dto.R;
import com.qf.entity.TDirtyWord;
import com.qf.service.DirtyWordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
杨威
2021/10/26
9:08
*/
@RestController
@RequestMapping("/word")
@Api("敏感词")
public class DirtyWordController {
    @Autowired
    private DirtyWordService dirtyWordService;
    @Autowired
    private TDirtyWordCache tDirtyWordCache;
    @GetMapping("/showAll")
    @ApiOperation("分页查询所有敏感词")
    public R showAll(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "3") Integer pageSize){
        List<TDirtyWord> allData = tDirtyWordCache.getAllData();
        return R.setOk(allData);
    }
    @GetMapping("/show/{id}")
    @ApiOperation("根据id查询敏感词")
    public R show(@PathVariable Long id){
        TDirtyWord dirtyWord = tDirtyWordCache.getById(id);
        return R.setOk(dirtyWord);
    }
    @PostMapping("/add")
    @ApiOperation("添加敏感词")
    public R add(TDirtyWord tDirtyWord){
        System.out.println("tDirtyWord = " + tDirtyWord);
        Integer add = dirtyWordService.add(tDirtyWord);
        return R.setOk(add);
    }
    @PostMapping("/modify")
    @ApiOperation("修改敏感词")
    public R modify(TDirtyWord tDirtyWord){
        Integer modify = dirtyWordService.modify(tDirtyWord);
        return R.setOk(modify);
    }
}
